﻿using OOPA_opdracht.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OOPA_opdracht
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                bool stayInLoop = true;
                while (stayInLoop)
                {
                    Console.WriteLine("Type out the name of the circuit you want to run.");
                    Console.WriteLine("Your choices are: input, circuit1, circuit2, circuit3 and circuit4");

                    string filename = Console.ReadLine();

                    switch (filename)
                    {
                        case "input":
                        case "circuit1":
                        case "circuit2":
                        case "circuit3":
                        case "circuit4": stayInLoop = startReading(filename); break;
                        case "quit": stayInLoop = false; break;
                        default: Console.WriteLine("Invalid circuit, try again..."); break;
                    }
                }

                Console.WriteLine("Shutting down...");
                Console.ReadLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.ReadLine();
            }
            
            
        }

        private static bool startReading(string filename)
        {
            Console.WriteLine("Begin reading " + filename + "...");
            Circuit circuit = new Circuit();
            circuit.read(filename);
            return readAnother();
        }

        private static bool readAnother()
        {
            bool validAnswer = false;
            while (!validAnswer)
            {
                Console.WriteLine("Do you want to run another circuit? Y/N");
                string wantToContinue = Console.ReadLine();
                switch (wantToContinue)
                {
                    case "y":
                    case "Y": Console.WriteLine("Ok, let's begin..."); return true;
                    case "n":
                    case "N": return false;
                    default: Console.WriteLine("Invalid response, "); break;
                }
            }

            return false;
        }
    }
}
